package com.u3k.app.mid.utils.common;

import android.content.Context;
import android.text.TextUtils;
import java.io.File;

public class PathUtil {
    static String APPID_KEY = "";

    public static boolean deleteFiles(String str) {
        int i = 0;
        if (str == null) {
            return false;
        }
        File file = new File(str);
        if (file.isFile()) {
            return file.delete();
        }
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            while (i < listFiles.length) {
                deleteFiles(listFiles[i].getAbsolutePath());
                i++;
            }
        }
        return file.delete();
    }

    public static String getAppIdKey() {
        return APPID_KEY;
    }

    public static File getCacheDir(Context context) {
        File file = new File(!TextUtils.isEmpty(APPID_KEY) ? context.getFilesDir().getAbsolutePath() + File.separator + APPID_KEY + File.separator + "cache" : context.getFilesDir().getAbsolutePath() + File.separator + "cache");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static String getDataPath(Context context) {
        String absolutePath = !TextUtils.isEmpty(APPID_KEY) ? context.getFilesDir().getAbsolutePath() + File.separator + APPID_KEY : context.getFilesDir().getAbsolutePath();
        File file = new File(absolutePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return absolutePath;
    }

    public static File getDatabaseDir(Context context) {
        File file = new File(!TextUtils.isEmpty(APPID_KEY) ? context.getFilesDir().getAbsolutePath() + File.separator + APPID_KEY + File.separator + "db" : context.getFilesDir().getAbsolutePath() + File.separator + "db");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static File getFilesDir(Context context) {
        File file = new File(!TextUtils.isEmpty(APPID_KEY) ? context.getFilesDir().getAbsolutePath() + File.separator + APPID_KEY + File.separator + "files" : context.getFilesDir().getAbsolutePath() + File.separator + "files");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static void initAppIdKey(String str) {
        APPID_KEY = str;
    }
}
